package controllers;

import java.util.Date;
import java.util.List;

import models.Acesso;
import models.Processo;
import play.modules.router.Get;
import play.mvc.Controller;
import play.mvc.With;
import controllers.Secure.Security;

@With(Secure.class)
public class Application extends Controller {
	
	@Check("isAdmin")
    public static void index() {
		String user = Security.connected();
        List<Object> acessos = Acesso.find("usuario.login = ? order by dataAcesso desc", user).fetch(5);
		render(acessos);
    }
	
	@Check("isAdmin")
    public static void previous(long dataAcesso) {
		String user = Security.connected();
        List<Object> acessos = Acesso.find("usuario.login = ? and dataAcesso > ? order by dataAcesso desc", user, new Date(dataAcesso)).fetch(5);
		render("Application/index.html", acessos);
    }
	
	@Check("isAdmin")
    public static void next(long dataAcesso) {
		String user = Security.connected();
        List<Object> acessos = Acesso.find("usuario.login = ? and dataAcesso < ? order by dataAcesso desc", user, new Date(dataAcesso)).fetch(5);
		render("Application/index.html", acessos);
    }
	
	@Check("isAdmin")
	@Get("/processo/{id}")
    public static void detalharProcesso(long id) {
		Processo processo = Processo.findById(id);
		render(processo);
    }
}